/**   
 * @Title: AgainstTeamListLocalFilter.java 
 * @Package com.esun.rabbit2.viewer.mainact.lotteryhallact.beidanagp 
 * @Description: 对阵列表本地筛选
 * @author: Kael gaojian@500wan.com   
 * @date: 2012-4-9 下午16:13:12  
 * Copyright: (C) 2011 Shenzhen E-sun Sky Net Technology Co.,ltd.
 */
package com.esun.rabbit2.viewer.mainact.lotteryhallact.beidanagp;
import java.util.ArrayList;
import java.util.Hashtable;
import com.esun.config.Config;
import com.esun.config.Key;
import com.esun.model.beijingdanchang.BeidanAgainstInfo;
import com.esun.util.log.EDebug;
/**
 * @ClassName: AgainstTeamListLocalFilter
 * @Description: 对阵列表本地筛选
 * @author: Kael gaojian@500wan.com   
 * @date: 2012-4-9 下午16:13:12 
 * 
 */
public class AgainstTeamListLocalFilter {
	private ArrayList<Hashtable<String, Object>> list = new ArrayList<Hashtable<String, Object>>();
	private int rangqiuType;//让球
	private int peilvType;//赔率
	private ArrayList<String> leagueNameList;//联赛名称列表

	public AgainstTeamListLocalFilter(ArrayList<Hashtable<String, Object>> list) {
		this.list = list;
	}

	/** 
	* @Title: getResult 
	* @Description: 获取筛选结果
	* @param: @param rangqiuType
	* @param: @param peilvType
	* @param: @param leagueNameList
	* @param: @param isAll
	* @param: @return    设定文件 
	* @return: ArrayList<Hashtable<String,Object>>    返回类型 
	* @throws 
	*/
	public ArrayList<Hashtable<String, Object>> getResult(int rangqiuType, int peilvType, ArrayList<String> leagueNameList, boolean isAll, boolean isPvAll) {
		this.rangqiuType = rangqiuType;
		this.peilvType = peilvType;
		this.leagueNameList = leagueNameList;
		for (int i = 0; i < list.size(); i++) {
			//BeidanAgainstInfo单例使用有误，暂时遗留
			if ((Boolean) list.get(i).get(Key.KEY_IS_TITLE)) {
				list.get(i).put(Key.KEY_IS_SHOW	, true);
			} else if ((isRightLeague((BeidanAgainstInfo) list.get(i).get(Key.KEY_INFO)) || isAll )
					&& isRightPeilv((BeidanAgainstInfo) list.get(i).get(Key.KEY_INFO), isPvAll)
					&& isRightRangqiu((BeidanAgainstInfo) list.get(i).get(Key.KEY_INFO))) {
				list.get(i).put(Key.KEY_IS_SHOW	, true);
			}else{
				list.get(i).put(Key.KEY_IS_SHOW	, false);
				list.get(i).put(Key.KEY_IS_ACTIVE, false);
				list.get(i).put(Key.KEY_W, false);
				list.get(i).put(Key.KEY_D, false);
				list.get(i).put(Key.KEY_L, false);
				list.get(i).put(Key.KEY_IS_DAN, false);
			}
		}
		return list;	
		
	}

	
	/** 
	* @Title: isRightRangqiu 
	* @Description: 0:全部,1:让球,2:非让球
	* @param: @param beiDanAgainstInfo
	* @param: @return    设定文件 
	* @return: boolean    返回类型 
	* @throws 
	*/
	private boolean isRightRangqiu(BeidanAgainstInfo beiDanAgainstInfo) {
		boolean b = false;
		if (rangqiuType == 0) {//全部
			b = true;
		} else if (rangqiuType == 1) {//让球
			if (beiDanAgainstInfo.getRangqiu().equals(Config.NUM0)) {
				b = false;
			} else {
				b = true;
			}
		} else if (rangqiuType == 2) {//非让球
			if (beiDanAgainstInfo.getRangqiu().equals(Config.NUM0)) {
				b = true;
			} else {
				b = false;
			}
		} else {
			b = false;
		}
		EDebug.o("让球type"+b);
		return b;
	}

	
	/** 
	* @Title: isRightPeilv 
	* @Description: 0:全部,1:高命中区间,2:实力赔率区间,3:高额回报区间
	* @param: @param beiDanAgainstInfo
	* @param: @return    设定文件 
	* @return: boolean    返回类型 
	* @throws 
	*/
	private boolean isRightPeilv(BeidanAgainstInfo beiDanAgainstInfo, boolean isPvAll) {
		boolean b = false;
		if(isPvAll){//全部
			b = true;
		}else{
			String c1 = beiDanAgainstInfo.getC1();//主胜的赔率
			if(c1.equals(Config.NULLMARK)){
				b = false;
			}else{
				double w = Double.parseDouble(beiDanAgainstInfo.getC1());

				if (peilvType == 0) {//全部
					b = true;
				} else if (peilvType == 1) {//高命中区间
					if (w < 1.5) {
						b = true;
					} else {
						b = false;
					}
				} else if (peilvType == 2) {//实力赔率区间
					if (w >= 1.5 && w <= 2) {
						b = true;
					} else {
						b = false;
					}

				} else if (peilvType == 3) {//高额回报区间
					if (w >= 2) {
						b = true;
					} else {
						b = false;
					}

				} else {
					b = false;
				}
			}
		}
		EDebug.o("赔率区间"+ b);
		return b;
	}

	
	/** 
	* @Title: isRightLeague 
	* @Description: 联赛筛选
	* @param: @param beiDanAgainstInfo
	* @param: @return    设定文件 
	* @return: boolean    返回类型 
	* @throws 
	*/
	private boolean isRightLeague(BeidanAgainstInfo beiDanAgainstInfo) {
		boolean b = false;
		for (int i = 0; i < leagueNameList.size(); i++) {
			String strItmeLeague = beiDanAgainstInfo.getSimpleLeague().replaceAll("\\s", Config.NULLMARK);
			String strOrderLeague = leagueNameList.get(i).replaceAll("\\s", Config.NULLMARK);
			if (strItmeLeague.equals(strOrderLeague)) {
				b = true;
				break;
			} else {
				b = false;
			}

		}
		EDebug.o("联赛"+b);
		
		return b;
	}
}
